$(function(){
	var history = localStorage.history ? JSON.parse(localStorage.history) : [];
	$('#searchbtn').on('tap',function(){
		// console.log(111);
		var keyword = $.trim($('.search>input').val());
		if (keyword == ''){
			mui.toast('请输入数据')
		}else{
			history.unshift(keyword);
			localStorage.history = JSON.stringify(history);
			getHis();
			location.href='search-result.html?keyword='+$.trim($('.search>input').val());
			$('.search>input').val('');
			
		}
	})
	getHis()
	function getHis() {
		history = localStorage.history ? JSON.parse(localStorage.history) : [];
		if(history.length == 0 ){
			$('.list-content>ul').html('<h1>暂无数据</h1>');
		} else {
			var html = template('historyList',history)
			$('.list-content>ul').html(html);
		}
	}
	$('.clear-history').on('tap', function () {
        localStorage.history = "[]"
        getHis()
    })
});